package com.mengniu.commerce.sync.controller;


import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.common.core.domain.R;
import com.mengniu.commerce.common.core.web.controller.BaseController;
import com.mengniu.commerce.common.log.annotation.Log;
import com.mengniu.commerce.common.log.enums.BusinessType;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.MemberInsertModel;
import com.mengniu.commerce.sync.api.domain.MemberModifyModel;
import com.mengniu.commerce.sync.api.domain.MemberRegisterModel;
import com.mengniu.commerce.sync.api.dto.RetryDTO;
import com.mengniu.commerce.sync.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 会员创建controller
 *
 * @author zfw
 */
@RestController
@RequestMapping("/member")
@Slf4j
public class MemberController extends BaseController
{
       @Autowired
    private MemberService memberService;

    @Log(title = "存量会员创建管理", businessType = BusinessType.INSERT)
    @PostMapping("/memberInsert")
    public R memberInsert(@RequestBody List<MemberInsertModel> createMemberModelList, String source)
    {
        log.info("存量会员创建参数为:{},{}", JSONObject.toJSONString(createMemberModelList),source);
        return memberService.memberInsert(createMemberModelList);

    }

    @Log(title = "会员创建管理", businessType = BusinessType.INSERT)
    @PostMapping("/memberRegister")
    public R memberRegister(@RequestBody @Valid MemberRegisterModel memberRegisterModel, String source, String userId)
    {
        log.info("会员创建管理:{},{}", JSONObject.toJSONString(memberRegisterModel),source);
        RetryDTO retryDTO = new RetryDTO();
        retryDTO.setSource("YZ");
        retryDTO.setStoreName("QY测试店铺");
        return memberService.memberRegister(memberRegisterModel,retryDTO,userId);

    }

    @Log(title = "会员修改管理", businessType = BusinessType.INSERT)
    @PostMapping("/memberModify")
    public R memberModify(@RequestBody @Valid MemberModifyModel memberModifyModel, String source)
    {
        log.info("会员修改参数为:{},{}", JSONObject.toJSONString(memberModifyModel),source);
        return memberService.memberModify(memberModifyModel,null);

    }



}
